Many computer programs use multiple execution contexts to perform work asynchronously and concurrently. Execution contexts include computers, processors, threads, or the like. One example of this is the use of multiple threads to perform work asynchronously. Typically, a thread or other execution context may maintain data such as an observable state or other local data that is not directly accessible to other threads or execution contexts. Problems may arise in a situation where an execution context performs actions that may use unavailable data. For example, one execution context may maintain settings for a user's locale or other preferences. Another execution context may perform actions without access to this data, causing the wrong locale or other preferences to be used. In another example, a program may have a user interface (UI) thread that processes UI notifications and updates the user interface, and one or more other threads that process other types of notifications or perform various operations. Problems may arise when instructions on one of the other threads attempts to update the user interface. This may cause conflicts and result in an exception and a program crash.
An example of this is a dictionary suggest application that looks up suggested corrections based on a word the user has typed. The UI thread may send a request for suggestions to a local or remote server. A handler executing on a secondary thread may receive the server's response and attempt to update the UI. This can cause an execution exception.
As a consequence of situations such as described above, it is desirable for program developers to have control over the execution context in which their program code executes. Various programming environments include a mechanism for moving a computation from one thread to another. These mechanisms may add a level of complexity or restrictions that are undesirable to a programmer, or have other limitations.